home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / Effect library / Demo ƒ / Fades ƒ / Circle out fade.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-11  |  2.7 KB  |  89 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        Circle out fade.c
  4.  
  5. Purpose:    Graphic effect to fade main window to solid pattern.
  6.             See comments below for more description.
  7.  
  8.  
  9. MSG Demo -- graphic effects demonstration program
  10. Copyright (C) 1992-4 Mark Pilgrim & Dave Blumenthal
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "msg timing.h"
  30.  
  31. #define    gap            4        /* difference between one radius and the next */
  32. #define CorrectTime 2
  33. #define theWindowHeight (boundsRect.bottom-boundsRect.top)
  34. #define theWindowWidth (boundsRect.right-boundsRect.left)
  35.  
  36. pascal short CircleOutFade(Rect boundsRect, Pattern *thePattern);
  37.  
  38. /* Make a circular region and use it as the mask in CopyBits.  Lots of overlap,
  39.    but masked by timing correction.  If you want to optimize it, look at the
  40.    donut region code in "Circle in.c" */
  41.    
  42. pascal short CircleOutFade(Rect boundsRect, Pattern *thePattern)
  43. {
  44.     Rect            theRect;
  45.     int                cx, cy;
  46.     RgnHandle        curregion, boundsRgn, sectrgn;
  47.     Point            zeroPoint;
  48.     
  49.     zeroPoint.h=boundsRect.left;
  50.     zeroPoint.v=boundsRect.top;
  51.     
  52.     cx = theWindowWidth / 2;
  53.     cy = theWindowHeight / 2;
  54.     
  55.     theRect.left=cx-gap;         /* circumscribing rectangle for circle */
  56.     theRect.right=cx+gap;
  57.     theRect.top=cy-gap;
  58.     theRect.bottom=cy+gap;
  59.     OffsetRect(&theRect, boundsRect.left, boundsRect.top);
  60.     
  61.     boundsRgn=NewRgn();
  62.     SetRectRgn(boundsRgn, boundsRect.left, boundsRect.top, boundsRect.right, boundsRect.bottom);
  63.     sectrgn=NewRgn();
  64.     curregion=NewRgn();
  65.     
  66.     do
  67.     {
  68.         StartTiming();
  69.         SetEmptyRgn(curregion);
  70.         OpenRgn();
  71.             FrameOval(&theRect);   /* the circle region */
  72.         CloseRgn(curregion);
  73.         SectRgn(curregion, boundsRgn, sectrgn);
  74.         FillRgn(sectrgn, *thePattern);
  75.         theRect.left-=gap;        /* make the rect bigger (and thus the circle) */
  76.         theRect.right+=gap;
  77.         theRect.top-=gap;
  78.         theRect.bottom+=gap;
  79.         TimeCorrection(CorrectTime);
  80.     }
  81.     while (!PtInRgn(zeroPoint, curregion));
  82.     
  83.     DisposeRgn(curregion);
  84.     DisposeRgn(boundsRgn);
  85.     DisposeRgn(sectrgn);
  86.     
  87.     return 0;
  88. }
  89.